const i18n = require('i18n');
/**
 * 接受鼠标鼠标操作
 */
cc.Class({
    extends: cc.Component,

    properties: {
        canvas: cc.Node,//点击组件
      
      
        player:{//角色组件
            default: null,
            type: cc.Node
        },

        startTouchPos:cc.v2(),//鼠标开始移动位置
        moveTouchDir:cc.v2(),//鼠标当前移动位置
        isMoving:false
    },

    SetDir:function(dir)
    {
        var play =  this.player.getComponent("HeroControl");
        play.SetDir(this);
    },
    SetStart :function()
    {
        var play =  this.player.getComponent("HeroControl");
        play.SetStart();
    },

    // use this for initialization
    onLoad: function () {
        var self = this;
        self.moveToPos = cc.v2(0, 0);
        self.isMoving = false;
        self.canvas.on(cc.Node.EventType.TOUCH_START, function (event) {
            var touches = event.getTouches();
            var touchLoc = touches[0].getLocation();
           
            self.startTouchPos = touchLoc;
            self.SetStart();
            
          }, self.node);
        self.canvas.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
            var touches = event.getTouches();
            var touchLoc = touches[0].getLocation();
            self. moveTouchDir = touchLoc;// touchLoc.sub(self.startTouchPos).normalize();
            self.SetDir(touchLoc);
            
            self.isMoving = true;
        }, self.node);
        self.canvas.on(cc.Node.EventType.TOUCH_END, function (event) {
            self.isMoving = false; // when touch ended, stop moving
        }, self.node);
    },

    // called every frame
    update: function (dt) {
         return;
       
    }
});
